#ifndef IVWQTINTERFACE_H
#define IVWQTINTERFACE_H

#include <QObject>
#include <QString>
#include "simple_kws.h"

class IvwQtInterface : public QObject
{
    Q_OBJECT
public:
    explicit IvwQtInterface(QObject *parent = nullptr);
    ~IvwQtInterface();

public slots:
    // Initializes the IVW/KWS module.
    // appID, apiKey, apiSecret: Credentials for AIKIT.
    // resourcePath: Path to the KWS resource file.
    // keywordCount: Number of keywords to recognize.
    bool init(const QString& appID, const QString& apiKey, const QString& apiSecret,
              const QString& resourcePath, int keywordCount);

    // Starts listening for keywords.
    bool startListening();

    // Stops listening for keywords.
    bool stopListening();

    // Cleans up IVW/KWS resources.
    void cleanup();

signals:
    // Emitted when a keyword is detected.
    void keywordDetected(const QString& keyword);

    // Emitted when an error occurs.
    void errorOccurred(const QString& errorMsg);

private:
    // Static callback functions to bridge C callbacks to Qt signals
    static void staticKeywordDetectedCallback(const char* keyword);
    static void staticErrorCallback(const char* errorMsg);

    // Pointer to the current instance to allow static callbacks to emit signals
    static IvwQtInterface* m_instance;

    QString m_appID;
    QString m_apiKey;
    QString m_apiSecret;
    QString m_resourcePath;
    int m_keywordCount;
    bool m_isInitialized;
};

#endif // IVWQTINTERFACE_H
